﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Interfaces
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.AddHandler(CloseableTabItem.CloseTabEvent, new RoutedEventHandler(this.CloseTab));
        }
        private void CloseTab(object source, RoutedEventArgs args)
        {
            TabItem tabItem = args.Source as TabItem;
            if (tabItem != null)
            {
                TabControl tabControl = tabItem.Parent as TabControl;
                if (tabControl != null)
                    tabControl.Items.Remove(tabItem);
            }
        }
        public void addTabItem(string header, UserControl content, bool closeable)
        {
            TabItem item;
            if (closeable)
                item = new CloseableTabItem();
            else
                item = new TabItem();
            item.Header = header;
            item.Content = content;
            Tab1.Items.Add(item);
            Tab1.SelectedIndex = Tab1.Items.Count - 1;
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            addTabItem("Prueba", new Ventas(), true);
        }
    }
}
